from peewee import *

from mxshop_src.user_srv.settings import settings


class BaseModel(Model):
    class Meta:
        database = settings.DB

class User(BaseModel):

    GENDER_CHOICES = (
        ("female", "女"),
        ("male", "男")
    )

    ROLE_CHOICES = (
        (1, "普通用户"),
        (2, "管理员")
    )

    mobile = CharField(max_length=11, index=True, unique=True, verbose_name="手机号码")
    password = CharField(max_length=100, verbose_name="密码")
    nickName = CharField(max_length=20, null=True, verbose_name="昵称")
    head_url = CharField(max_length=200, null=True, verbose_name="头像")
    birthday = DateField(null=True, verbose_name="生日")
    address = CharField(max_length=200, null=True, verbose_name="地址")
    desc = TextField(null=True, verbose_name="个人简介")
    gender = CharField(max_length=11, choices=GENDER_CHOICES, null=True, verbose_name="性别")
    role = IntegerField(default=1, choices=ROLE_CHOICES)

USERLISTS = User.select()

if __name__ == "__main__":
    settings.DB.create_tables([User])


    # for i in range(5):
    #     user = User()
    #     user.nickName = f"bobby{i}"
    #     user.mobile = f"1829765135{i}"
    #     user.password = "admin123"
    #
    #     user.save()

    users = User.select()

    for user in users:
        print(user.mobile)
